use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear generate femXsoc=female*socst regress write female socst femXsoc twoway (lfit write socst if ~female)(lfit write socst if female), legend(off) global mean = r(mean) global sd = r(sd) /* create new variable centered at the mean of socst */ generate mean = socst-$mean generate femXmean=female*mean regress write female mean femXmean twoway (lfit write socst if ~female)(lfit write socst if female), legend(off) scheme(s2mono) xline($mean) xtitle(socst with verticle line at mean) local classlist="josh jim tony" foreach name in `classlist'{ disp `name' } disp `classlist' *************************************** xtile science_half = science, nq(2) * baby question: are reading scores balanced between M/F in in the bottom half of science scores? reg read female if science_half==1 ttest(read) if science_half==1, by(female) if (r(p)<0.05) { disp "yes" } else { disp "no" } local joshvars read write math foreach josh in `joshvars'{ ttest(`josh') if science_half==1, by(female) if (r(p)<0.05) { disp "`josh': IS balanced" } else { disp "`josh': is NOT balanced" } } local joshvars read write math drop count gen count = 0 foreach josh in `joshvars'{ ttest(`josh') if science_half==1, by(female) replace count = count + (r(p)<.05) } gen fraction = count / 3 sum fraction ttest(write) if science_half==1, by(female) replace count = count + (r(p)<.05) ttest(math) if science_half==1, by(female) replace count = count + (r(p)<.05)